home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!xmission!news
- From: tknarr@xmission.com ( Todd Knarr )
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Subject: Re: Undefined behavior? on type conversion, was: Re: Hungarian notation
- Date: 3 Feb 1996 05:28:26 GMT
- Organization: Chaos Central
- Message-ID: <4eurpq$b75@news.xmission.com>
- References: <30C40F77.53B5@swsbbs.com> <4d2ok0$69s@beach.and.nl> <4er2qo$h2s@galaxy.ucr.edu> <31118641.6802368@nntp.ix.netcom.com>
- Reply-To: tknarr@xmission.com ( Todd Knarr )
- NNTP-Posting-Host: slc113.xmission.com
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <31118641.6802368@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
- >> : |> Repeating the quote from ISO 6.2.1.2
- >> :
- >> : |> When a value with integral type is demoted to a signed integer
- >> : |> with smaller size or an unsigned integer is converted to its
- >> : |> corresponding signed integer, if the value cannot be
- >> : |> represented the result is implementation defined.
-
- >Consider a machine with 8 bit char and the expression
- >
- > (char) 256
- >
- >Here we have correct syntax and correct data. The standard says that
- >this converts the number 256 to a char. I believe I have a right to
- >assume that this will be done.
-
- Except that 6.2.1.2 says you can't assume that. Your particular
- implementation may let you assume that, but the standard doesn't
- require it to. On machines with the capability of extracting the
- low-order bits the reasonable thing to do would be to fill in the
- char with the low-order byte ( 0 in your example ), but the
- standard doesn't say the machine has to have that capability, or
- that the implementation has to excercise it, or that the implementation
- has to be reasonable. As I asked before, do you think that, on a
- machine where the natural hardware response to your example would be
- a machine check and system halt, the committee intended to require
- that the compiler insert a range check before every such conversion?
-
- As for "result" vs. "behavior", while I don't have the standard in
- front of me I believe that in the case of the ++ and -- operators the
- side-effect increment and decrement is also referred to as a result.
- If that is so, then their use of "result" doesn't rule out side-effects
- in the conversion, which can be anything since the implementation gets
- to define them.
-
- Can you tell I tend to read the standard conservatively? I've been
- burned once too often by assuming things that weren't explicitly
- spelled out.
-
- --
- Todd Knarr : tknarr@xmission.com | finger for PGP public key
- | Member, USENET Cabal
-
- Seriously, I don't want to die just yet. I don't care how
- good-looking they are, I! don't! want! to! die!"
- -- Megazone ( UF1 )
-
-